package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.adapter.tabadapter.OyAdapter;
import com.scoy.honeymei.bean.GoodsBean;
import com.scoy.honeymei.databinding.ItemMallMainBinding;
import com.scoy.honeymei.utils.GlideImgUtil;

import org.jetbrains.annotations.NotNull;

/**
 * 描述：添加类的描述
 *
 * @author 金源
 * @time 2021/1/20
 */
public class MallMain1Adapter extends OyAdapter<GoodsBean> {


    public MallMain1Adapter(Context context) {
        super(context);
    }

    @NonNull
    @NotNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        ItemMallMainBinding binding = ItemMallMainBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new MallMain1Adapter.MallMainsHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {
        MallMain1Adapter.MallMainsHolder mHolder = (MallMain1Adapter.MallMainsHolder) holder;
        GoodsBean mBean = datalist.get(position);

        GlideImgUtil.glidePic(context, mBean.getImage(), mHolder.binding.immIv);
        mHolder.binding.immNameTv.setText(mBean.getName());
        mHolder.binding.immPriceTv.setText("¥" + mBean.getMoney());
        mHolder.binding.immSalesTv.setText("库存:" + mBean.getStock());
        mHolder.binding.immShopTv.setText(mBean.getShop_name());
        mHolder.binding.immToshopLlt.setVisibility(View.GONE);
        GlideImgUtil.glidePic(context, mBean.getShop_image(), mHolder.binding.immShopCiv);

        mHolder.itemView.setOnClickListener(v -> {
            if (onOneClick != null) {
                onOneClick.oneClick(position);
            }
        });
        mHolder.binding.immToshopLlt.setOnClickListener(v -> {
            if (onTwoClick != null) {
                onTwoClick.twoClick(position);
            }
        });

    }

    static
    class MallMainsHolder extends RecyclerView.ViewHolder {
        private ItemMallMainBinding binding;

        MallMainsHolder(ItemMallMainBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
